package jtacck.labmedicine;

import java.util.LinkedHashMap;
import java.util.List;

import jvm.jtacck.db.records.ClientSite;
import jvm.jtacck.db.records.Hospital;
import jvm.jtacck.db.records.ShippingInformation;
import jvm.jtacck.db.records.User;
import jvm.jtacck.serials.Route;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

public class RouteListener implements OnItemClickListener {
    private Activity main;
    private User user;
    
    protected RouteListener(Activity main) {
        this.main = main;
    }
    
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        // TODO Auto-generated method stub
        //user = new User("uname", "passcode", "John", "Smith", )
        ListView list = (ListView) parent.findViewById(R.id.route_screen_list);
        int i = list.getCheckedItemPosition();
        Route r = MainActivity.route;
        Bundle extras = new Bundle();
        if (r != null) {
            int j = 0;
            for (Hospital h : r.route.keySet()) {
                List<ClientSite> sites = r.route.get(h);
                for (ClientSite s : sites) {
                    RouteData data = MainActivity.cache.getRouteData();
                    data.addHospital(h, new LinkedHashMap<ClientSite, List<ShippingInformation>>());
                    if (i == j) {
                        MainActivity.currentSite = s;
                        MainActivity.sList = null;
                    }
                    j++;
                }
            }
        }
        
//        extras.putStringArray("toDo", MainActivity.currentSite.instructions.toArray(new String[0]));
        extras.putSerializable("nextActivity", ChecklistActivity.class);
        extras.putSerializable("serverRequest", MainActivity.currentSite);
        extras.putString("state", "SITE");
        Intent intent = new Intent(main,ChecklistActivity.class);
        intent.putExtra("jtacck", extras);
        main.startActivity(intent);
    }

}
